<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%
	pageContext.setAttribute("ctx", request.getContextPath());	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>新增账号</title>

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" /><!-- 控制浏览器文件模式为IE8 -->
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="js/artDialog/skins/default.css" rel="stylesheet" type="text/css" />
<link href="css/sele.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/artDialog/artDialog.js?skin=blue"></script>
<script src="js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="js/operamasks-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/elegant/om-all.css" />
<link rel="stylesheet"  type="text/css" href="${ctx}/css/default.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/jqueryeasyui12/themes/bootstrap/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/js/jqueryeasyui12/themes/icon.css" />
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/jquery.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/jqueryeasyui12/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">.datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber{-o-text-overflow: ellipsis;text-overflow: ellipsis;}</style>

<script> 
(function (config) {
    config['lock'] = true;
    config['fixed'] = true;
    config['okVal'] = 'Ok';
    config['cancelVal'] = 'Cancel';
})(art.dialog.defaults);
</script>
<%-- <script language="javascript">
	var j = jQuery.noConflict();
	j.ajaxSetup({
		cache:false,
		async: false
	});
</script> --%>
<script>

	var ctx = '${ctx}';
	
	/**
	datagrid增加ToolTip
	*/
	$.extend($.fn.datagrid.methods, {
	    /**
	    * 开打提示功能
	    * @param {} jq
	    * @param {} params 提示消息框的样式
	    * @return {}
	    */
	    doCellTip: function (jq, params) {
	        function showTip(data, td, e) {
	            if ($(td).text() == "")
	                return;
	            data.tooltip.text($(td).text()).css({
	                top: (e.pageY + 10) + 'px',
	                left: (e.pageX + 20) + 'px',
	                'z-index': $.fn.window.defaults.zIndex,
	                display: 'block'
	            });
	        };
	        return jq.each(function () {
	            var grid = $(this);
	            var options = $(this).data('datagrid');
	            if (!options.tooltip) {
	                var panel = grid.datagrid('getPanel').panel('panel');
	                var defaultCls = {
	                    'border': '1px solid #333',
	                    'padding': '2px',
	                    'color': '#333',
	                    'background': '#f7f5d1',
	                    'position': 'absolute',
	                    'max-width': '200px',
	                    'border-radius': '4px',
	                    '-moz-border-radius': '4px',
	                    '-webkit-border-radius': '4px',
	                    'display': 'none'
	                }
	                var tooltip = $("<div id='celltip' style='font-size:9px;'></div>").appendTo('body');
	                tooltip.css($.extend({}, defaultCls, params.cls));
	                options.tooltip = tooltip;
	                panel.find('.datagrid-body').each(function () {
	                    var delegateEle = $(this).find('> div.datagrid-body-inner').length ? $(this).find('> div.datagrid-body-inner')[0] : this;
	                    $(delegateEle).undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove').delegate('td', {
	                        'mouseover': function (e) {
	                            if (params.delay) {
	                                if (options.tipDelayTime)
	                                    clearTimeout(options.tipDelayTime);
	                                var that = this;
	                                options.tipDelayTime = setTimeout(function () {
	                                    showTip(options, that, e);
	                                }, params.delay);
	                            }
	                            else {
	                                showTip(options, this, e);
	                            }
	
	                        },
	                        'mouseout': function (e) {
	                            if (options.tipDelayTime)
	                                clearTimeout(options.tipDelayTime);
	                            options.tooltip.css({
	                                'display': 'none'
	                            });
	                        },
	                        'mousemove': function (e) {
	                            var that = this;
	                            if (options.tipDelayTime)
	                                clearTimeout(options.tipDelayTime);
	                            //showTip(options, this, e);
	                            options.tipDelayTime = setTimeout(function () {
	                                showTip(options, that, e);
	                            }, params.delay);
	                        }
	                    });
	                });
	
	            }
	
	        });
	    },
	    /**
	    * 关闭消息提示功能
	    *
	    * @param {}
	    *            jq
	    * @return {}
	    */
	    cancelCellTip: function (jq) {
	        return jq.each(function () {
	            var data = $(this).data('datagrid');
	            if (data.tooltip) {
	                data.tooltip.remove();
	                data.tooltip = null;
	                var panel = $(this).datagrid('getPanel').panel('panel');
	                panel.find('.datagrid-body').undelegate('td', 'mouseover').undelegate('td', 'mouseout').undelegate('td', 'mousemove')
	            }
	            if (data.tipDelayTime) {
	                clearTimeout(data.tipDelayTime);
	                data.tipDelayTime = null;
	            }
	        });
	    }
	});
	
	//頁面初始化
	jQuery(document).ready(function(){
	    
	    //選擇父級組織
	    $('#chooseParent').click(function() {
	    	var optionWinParent = $("#optionWinParent");
			optionWinParent.find("input").val("");
			optionWinParent.find("select").val("");
			if (optionWinParent.is(':visible')){
				;
			}else{
				optionWinParent.slideDown();//显示 
			} 
			optionWinParent.window('open');
			
	    	var params={
	    			"f_enable" : "1"
	    	};
			$('#qryOrgParentGrid').datagrid({
				//title:'組織代碼信息',
				nowrap: true,
				onLoadSuccess: function (data) {
	                $(this).datagrid('doCellTip', { 'max-width': '700px', 'delay': 500 });
	            },
				striped: true,
				fitColumns: false,
				url: ctx+'/org.do?action=orgList',
				remoteSort: false,
			    queryParams:params,
				idField:'orgId',
				singleSelect:true,
				rownumbers:true,
				frozenColumns:[[
	                {field:'ck',checkbox:true,width:30},
	                {title:'orgId',field:'orgId',width:30,hidden:true},
	                {title:'levelId',field:'levelId',width:30,hidden:true},
	                {field:'parentId',title:'parentId',width:120,hidden:true},
	                {field:'dominate',title:'廠區',width:100},
	                {field:'orgCode',title:'組織代碼',width:150},
				    {field:'orgName',title:'組織名稱',width:100}
				]],
				columns:[[
				    {field:'orgFee',title:'費用代碼',width:120},
				    {field:'levelName',title:'組織層級',width:120},
				    {field:'leaderNo',title:'主管工號',width:120},
				    {field:'leaderName',title:'主管姓名',width:120},
				    {field:'enable',title:'是否有效',width:120,
				    	formatter:function(value,rowData,rowIndex) {
							if(rowData.enable=='1') {
								return "有效";
							} else {
								return "無效";
							}
				    	}		
				    },
				    {field:'parentCode',title:'上級組織代碼',width:120},
				    {field:'parentName',title:'上級組織名稱',width:120},
				    {field:'createName',title:'創建人',width:100},
				    {field:'createTime',title:'創建時間',width:100}
				]],
				pagination:true,
				pageSize:10,
				pageNumber:1,
				pageList:[10,20,30]
			});
			
			$('#qryOrgParentGrid').datagrid('unselectAll');
	    });
	    $('#submitOrgParent').click(function() {
	    	var selected = $('#qryOrgParentGrid').datagrid('getSelected');
	    	if(selected){ 
	    		$("#orgId").val(selected.orgId);
		    	$("#orgName").val(selected.orgName);
		    	$("#optionWinParent").window('close');
	    	} else {
	    		$.messager.alert('系統提示','請先選擇一個組織!','warning');
	    	}
	    });
	    $('#cancelOrgParent').click(function() {
			$("#optionWinParent").window('close');
		});
	});

	var uflag = false;
 
	function submitForm() {
		var name = document.getElementById("userName").value;
		var password = document.getElementById("password").value;
		var repassword = document.getElementById("repassword").value; 
		var realName = document.getElementById("realName").value;
		var telePhone = document.getElementById("telePhone").value;
		var orgId = document.getElementById("orgId").value;
		
		var flag = true;
		if(name == null || name == ""){
			art.dialog.tips('用户名称不能为空！', 1.5);
			flag = false;
			return;	
		}
		if(password == null || password == ""){
			art.dialog.tips('密码不能为空！', 1.5);
			flag = false;
			return;
		}
		if(repassword != password){
			art.dialog.tips('两次密码输入不一致！', 1.5);
			flag = false;
			return;
		} 
		if(telePhone == null || telePhone == ""){
			art.dialog.tips('分机不能为空！', 1.5);
			flag = false;
			return;
		}
		var m = /^\d{3}\+\d{5}|\d{4}\+\d{4}$/;
		if(!m.test(telePhone)){
			art.dialog.tips('分机格式不正确！', 1.5);
			flag = false;
			return;
		}
		if(realName == null || realName == ""){
			art.dialog.tips('真实名不能为空！', 1.5);
			flag = false;
			return;
		}
		if(orgId == null || orgId == ""){
			art.dialog.tips('部門不能为空！', 1.5);
			flag = false;
			return;
		}
		if(uflag == false){
			art.dialog.tips('该帳號已经被使用或該員工不存在，请重新输入！', 1.5);
			flag = false;
			return;
		}
		var email = document.getElementById("email").value;
		var phone = document.getElementById("phone").value;		
		if(email == null || email == ""){
		}else{
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(email)) {
			 	art.dialog.tips('您的电子邮件格式不正确！', 1.5);
			 	flag=false;
				return ;
			 }
		}
		var patrn = /^(13[0-9]|15[0-9]|18[0-9]|14[0-9])\d{8}$/; //检测手机号码	
		if(phone == null || phone == ""){}else{
			if(!patrn.test(phone)){
				art.dialog.tips('您的手机号码格式不正确！', 1.5);
				flag = false;
				return false;
			}
		}
		if(flag){
			document.forms[0].submit();
		}
	}
	function checkName(obj){
		var t=/.*[\u4e00-\u9fa5]+.*$/;
		if(obj != ""){
			if(t.test(obj)){
				art.dialog.tips('不能包含汉字！', 1.5);
			}
			else {$.ajax( {
				url : './adminUser.do?action=checkName&userName='+obj,
				date : '',
				type : 'GET',
				dateType : 'xml',
				timeout : 100000,
				error : function(xml) {
					$.omMessageBox.alert({
				           content:'响应失败！',
				           onClose:function(v){}
				    });
				},
				success : function(xml) {
					var $message = $(xml).find("user").children("stat").text();
					if ($message == 'have') {
						uflag = false;
						$.omMessageBox.alert({
					           content:'警告信息：该帳號已经被使用或該員工不存在，请重新输入！',
					           onClose:function(v){document.getElementById("userName").value = "";}
					    });
					} else if($message == 'notipebg') {
						$.omMessageBox.alert({
					           content:'警告信息：该員工尚沒開通一帳通賬號，請先開通一帳通賬號！',
					           onClose:function(v){document.getElementById("userName").value = "";}
					    });
					} else if($message == 'timeout') {
						$.omMessageBox.alert({
					           content:'警告信息：已超时，请重新登录！',
					           onClose:function(v){window.parent.parent.location.href="login.jsp"}
					    });
					}else{
						uflag = true;
						return;
					}
				}
			});
			}
		}
	}
</script>
</head>
<body>

	<div class="place">
	    <span>位置：</span>
	    <ul class="placeul">
	    <li>首页</li>
		<li>系统管理</li>
	    <li><a href="#" onclick="javascript:window.location.href='./adminUser.do?action=list'"> 账号管理</a></li>
		<li>新增账号</li>
	    </ul>
    </div>
    <div class="rightinfo">
		<form id="form1" action="./adminUser.do?action=addUser" method="post">

			<ul class="seachform">
				<li>
					<label>工號：</label>
					<input id="userName" type="text" onblur="checkName(this.value);" name="loginName" size="10" style="width:100px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>密码：</label>
				    <input id="password" type="password" name="password" size="10" style="width:113px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>确认密码：</label>
					<input id="repassword" type="password" size="10" style="width:113px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>&nbsp;&nbsp;&nbsp;电话：</label>
				    <input id="phone" type="text" name="phone" size="10" style="width:113px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>分机：</label>
					<input id="telePhone" type="text" name="telePhone" size="10" style="width:100px;height:32px;" class="scinput" autocomplete="off"/><i>参考格式：579+25630/5126+6754</i>
				</li>
			</ul>
			<ul class="seachform">
				<li>
					<label>姓名：</label>
					<input id="realName" type="text" name="realName" size="10" style="width:100px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				
				<li>
					<label>部門：</label>
					<input id="orgId" type="hidden" name="orgId" />
					<input id="orgName" type="text" name="orgName" readonly="readonly" size="10" style="width:100px;height:32px;" class="scinput" autocomplete="off"/>
					<a id="chooseParent" href="#" class="easyui-linkbutton">選擇</a>
				</li>
				
				<li>
					<label>廠區：</label>
					<select id="dominate" name="dominate" style="width: 113px">
						<option value=""></option>
						<option value="ZZK">鄭州綜保區</option>
						<option value="ZZC">鄭州加工區</option>
						<option value="JYX">濟源</option>
						<option value="JCX">晉城</option>
						<option value="LHX">龍華</option>
						<option value="GLX">觀瀾</option>
						<option value="HBX">鶴壁</option>
						<option value="NH">內湖廠</option>
					</select>
				</li>
				
				<li>
					<label>E-mail：</label>
					<input id="email" type="text" name="email" size="10" style="width:113px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
				<li>
					<label>描述：</label>
					<input id="description" type="text" name="description" size="10" style="width:200px;height:32px;" class="scinput" autocomplete="off"/>
				</li>
			</ul>
        <table class="tablelist">
				<thead>
					<tr>
						<td>序号</td>
            			<td>角色名称</td>
            			<td>角色分配</td>
					</tr>
				</thead>
				<tbody>
					<c:set var="i" value="0" />
				<c:forEach var="list" items="${roleList}">
					<c:set var="i" value="${i+1}" />
					<tr>
						<td>${i }</td>
						<td>${list.roleName}</td>
						<td><input type="checkbox" style="width:20px;" name="roleId" value="${list.roleId }" <c:if test="${list.roleCode=='ROLE_NORMAL_SIGN_USER'}">checked="checked"  </c:if>/></td>
			        </tr>
		        </c:forEach>
				</tbody>
			</table>
          	<ul class="forminfo" style="margin-top:30px;">
			    <li>
					<label>&nbsp;</label>
					<input name="" type="button" id="save" onclick="submitForm();" class="btn" value="确定创建"/> 
					<input style="margin-left:100px;" onclick="javascript:document.location.href = './adminUser.do?action=list';" type="button" class="cancel" value="取消创建" />
				</li>
		    </ul>   
	    </form>
	</div>
	
	<div id="optionWinParent" class="easyui-window" title="選擇部門" closed="true" closable="true" modal="true"  
	     collapsible="false" minimizable="false" maximizable="false" draggable="true" resizable="false"
	     style="width:1000px;height:450px;padding:5px;left:60px;top:50px;background: #fafafa;display:none" align="center">
	     	<div style="width: 100%;height: 100%;overflow:auto;">
				<table id="qryOrgParentGrid" toolbar="#tbOrgParent"></table>
		    	<div id="tbOrgParent">
					<form action="" id="tbFormOrgParentId" style="margin:0px;margin-bottom:10px;">
						<table width="100%" id="tableShowOrgParent">
							<tr>
								<td width="40%" style="white-space:nowrap;padding-right:20px" align="right">
				                                                             組織代碼：<input  name="f_orgCode" id="s_orgCode" size="8"  type="text"/>
				                                                             組織名稱：<input  name="f_orgName" id="s_orgName" size="8"    type="text"/>
				          	               <input  name="f_enable" id="s_enable" size="8"    type="hidden"/>
				          	               <%-- <select name="f_enable" id="s_enable" class="easyui-validatebox">
											<option value=""></option>
											<option value="1">有效</option>
											<option value="0">無效</option>
										  </select> --%>
									<a href="#" id="btnreset" class="easyui-linkbutton" iconCls="icon-sync" plain="true" onclick="resetParent()">重置</a>
									<a class="easyui-linkbutton" iconCls="icon-search" plain="true" href="#" onclick="queryOrgParentByParams()">查询</a>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div style="padding:5px;text-align:center;">
					<a id="submitOrgParent" href="#" class="easyui-linkbutton" icon="icon-ok">確定</a>
					&nbsp;&nbsp;&nbsp;
					<a id="cancelOrgParent" href="#" class="easyui-linkbutton" icon="icon-cancel">取消</a>
				</div>
			</div>
		</div>
	
</body>
<script type="text/javascript">
window.onload = function()
{
	var isAddSuccess = '${isAddSuccess}';
	if(isAddSuccess == "success"){
		$.omMessageBox.alert({
			content:'添加成功！',
			onClose:function(v){
				document.location.href = './adminUser.do?action=list';
			}
	    });
	}
	else if(isAddSuccess == "error"){
		$.omMessageBox.alert({
			content:'添加失败！',
			onClose:function(v){}
	    });
	}
};
</script>
</html>